package com.jeff.springWebTestNG.service;


import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeff.springWebTestNG.TracingService;
import com.jeff.springWebTestNG.persistence.data.User1;
import com.jeff.springWebTestNG.persistence.service.IUser1Persister;
import com.jeff.springWebTestNG.service.exception.Exception1;
import com.jeff.springWebTestNG.service.exception.Exception2;

@Service
@TracingService
public class ServiceA implements IServiceA, ITarget {
	private IServiceB serviceB;
	@Autowired
	public void setServiceB(IServiceB serviceB) {
		this.serviceB = serviceB;
	}
	
	private IServiceC serviceC;
	@Resource
	public void setServiceC(IServiceC serviceC) {
		this.serviceC = serviceC;
	}
	
	private IServiceD serviceD1;
	@Autowired
	public void setServiceD1(IServiceD serviceD1) {
		this.serviceD1 = serviceD1;
	}
	
	private IServiceD serviceD2;
	@Autowired
	public void setServiceD2(IServiceD serviceD2) {
		this.serviceD2 = serviceD2;
	}
	
	private IServiceD serviceD;
	@Autowired
	@Qualifier("serviceD2")
	public void setServiceD(IServiceD serviceD) {
		this.serviceD = serviceD;
	}
	
	private IUser1Persister user1Persister;
	@Autowired
	public void setUser1Persister(IUser1Persister user1Persister) {
		this.user1Persister = user1Persister;
	}
	
	@Override
	public void printB() {
		// TODO Auto-generated method stub
		serviceB.printMe();
	}
	
	@Override
	public void printC() {
		// TODO Auto-generated method stub
		serviceC.printMe();
	}
	
	@Override
	public void printD() {
		// TODO Auto-generated method stub
		serviceD1.printMe();
		serviceD2.printMe();
		serviceD.printMe();
	}
	
	@Override
	public String hasReturnMethod1() {
		String ret = "Before Return Value..";
		
		return ret += "And After!";
	}
	
	@Override
	public void throwExceptions() throws Exception1, Exception2 {
		boolean switcher = false;
		if (switcher) throw new Exception2();
		
		if (!switcher) throw new Exception1();
	}
	
	@Override
	@Transactional
	public void tryCreateUser() {
		// TODO Auto-generated method stub
		User1 user = new User1();
		user.setName("Jeff");
		user.setAge(30);
		user1Persister.create(user);
	}
}
